
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <title>k8s镜像下载不下来？利用 github Action 自己动手一次性解决难题，丰衣足食</title>
            </head>
            <body>
            <a href="https://andyoung.blog.csdn.net">原作者博客</a>
            <div id="content_views" class="markdown_views prism-atom-one-light">
                    <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
                        <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
                    </svg>
                    <h2><a id="dockerimagesyncerhttpsgithubcomadmin4jdockerimagersync_1"></a><a href="https://github.com/admin4j/docker-imager-sync">docker-image-syncer</a></h2> 
<p>无论是在学习k8s还是正式环境部署k8s中,第一步安装k8难倒了各大英雄好汉。原因是k8s 各种组件镜像在谷歌服务器上(k8s.gcr.io)，而我们有墙的存在，所以会经常性的下载失败。解决办法是搭梯子，或者是使用其他镜像源。</p> 
<p>本仓库使用 aliyun image-syncer 配合 github action 同步 k8s docker镜像(k8s.gcr.io) 到 dockerhub。提高k8s docker镜像(k8s.gcr.io)成功率，解决云原生第一大难题。</p> 
<p>docker-image-syncer 运行原理</p> 
<ol><li> <p><code>docker pull</code> 下拉所需镜像</p> 
  <blockquote> 
   <p>由于github action 运行再国外的github服务器的，没有qiang一说，docker pull 是很方便的</p> 
  </blockquote> </li><li> <p><code>docker tag</code> 修改镜像tag</p> </li><li> <p><code>docker push</code> 推送镜像到相应docker register</p> </li></ol> 
<h2><a id="Getting_Started_17"></a>Getting Started</h2> 
<h3><a id="1__19"></a>1. 方式一</h3> 
<p>提交 PR ，和合并到 main 分支之后，自动执行github action同步到 dockerhub</p> 
<p><img src="https://i-blog.csdnimg.cn/blog_migrate/b819f15be38a1c7f66c34e40bb0a2821.png#pic_center" alt="image-20221213101819817"></p> 
<h3><a id="2__25"></a>2. 方式二</h3> 
<p>2.1、fork 这个仓库, 创建你自己的docker register 账号密码:</p> 
<ul><li> 
  <ol><li>Settings</li></ol> </li><li> 
  <ol start="2"><li>Secrets</li></ol> </li><li> 
  <ol start="3"><li>New Repository Secrets</li></ol> </li><li> 
  <ol start="4"><li>Add your DOCKER_USERNAME and DOCKER_PASSWORD key values.</li></ol> </li></ul> 
<p><img src="https://i-blog.csdnimg.cn/blog_migrate/a89da4d18759146c0e65e926ea204988.png#pic_center" alt="image-20221213102110118"></p> 
<p>2.2、修改<code>images.json</code> 文件，改成你需要的</p> 
<pre><code>{
  "quay.io/coreos/kube-rbac-proxy": "admin4j/kube-rbac-proxy",
  "k8s.gcr.io/metrics-server/metrics-server": "admin4j/metrics-server",
  "k8s.gcr.io/ingress-nginx/controller": "admin4j/ingress-nginx-controller",
  "k8s.gcr.io/git-sync/git-sync": "admin4j/git-sync",
  "gcr.io/kaniko-project/executor:debug,latest": "admin4j/kaniko-executor",
  "k8s.gcr.io/kube-state-metrics/kube-state-metrics": "admin4j/kube-state-metrics",
  "k8s.gcr.io/sig-storage/nfs-subdir-external-provisioner": "admin4j/nfs-subdir-external-provisioner",
  "k8s.gcr.io/prometheus-adapter/prometheus-adapter": "admin4j/prometheus-adapter",
  "k8s.gcr.io/kube-apiserver": "admin4j/kube-apiserver",
  "k8s.gcr.io/kube-controller-manager": "admin4j/kube-controller-manager",
  "k8s.gcr.io/kube-scheduler": "admin4j/kube-scheduler",
  "k8s.gcr.io/kube-proxy": "admin4j/kube-proxy",
  "k8s.gcr.io/pause": "admin4j/pause",
  "k8s.gcr.io/etcd": "admin4j/etcd",
  "coredns/coredns": "admin4j/coredns"
}
</code></pre> 
<p>修改<code>auth.json</code>，可以添加其他 docker register源</p> 
<pre><code class="prism language-yaml"><span class="token punctuation">{<!-- --></span>
  <span class="token key atrule">"registry.hub.docker.com"</span><span class="token punctuation">:</span> <span class="token punctuation">{<!-- --></span>
    <span class="token key atrule">"username"</span><span class="token punctuation">:</span> <span class="token string">"${USERNAME}"</span><span class="token punctuation">,</span>
    <span class="token key atrule">"password"</span><span class="token punctuation">:</span> <span class="token string">"${PASSWORD}"</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> 
<p>2.3、检查 action logs</p> 
<p><img src="https://i-blog.csdnimg.cn/blog_migrate/a828dc93aba27d99182a2a6c7282cbc7.png#pic_center" alt=""></p> 
<h2><a id="Action__74"></a>Action 执行完后,检查成果</h2> 
<p>dockerhub</p> 
<p><img src="https://i-blog.csdnimg.cn/blog_migrate/e6142a8f71fab2e3a0ce911677e38e38.png#pic_center" alt="image-20221213102633683"></p> 
<h2><a id="k8s_80"></a>k8s使用镜像</h2> 
<ol><li>方式一</li></ol> 
<pre><code># 在安装kubernetes集群之前，必须要提前准备好集群需要的镜像，所需镜像可以通过下面命令查看
[root@master ~]# kubeadm config images list

# 下载镜像
# 此镜像在kubernetes的仓库中,由于网络原因,无法连接，下面提供了一种替代方案
images=(
    kube-apiserver:v1.23.15
	kube-controller-manager:v1.23.15
	kube-scheduler:v1.23.15
	kube-proxy:v1.23.15
	pause:3.6
	etcd:3.5.1-0
	coredns/coredns:v1.8.6
)

for imageName in ${images[@]} ; do
	docker pull admin4j/$imageName
	docker tag admin4j/$imageName 		k8s.gcr.io/$imageName
	docker rmi admin4j/$imageName
done

</code></pre> 
<ol start="2"><li> <p>方式二</p> <p>直接修改 yml 部署文件的 image 属性</p> </li></ol> 
<h2><a id="_112"></a>仓库地址</h2> 
<p><a href="https://github.com/admin4j/docker-imager-sync">https://github.com/admin4j/docker-imager-sync</a><br> <a href="https://github.com/AliyunContainerService/image-syncer">https://github.com/AliyunContainerService/image-syncer</a><br> <a href="https://hub.docker.com/repositories/admin4j" rel="nofollow">https://hub.docker.com/repositories/admin4j</a></p>
                </div>
            </body>
            </html>
            